import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { TreeSelect } from 'antd';

class TreeMultiSelect extends Component {

  constructor(props) {
    super(props);
    this.state = {value: []};
  }

  onChange = (value) => {
    this.setState({ value });
    this.props.onChange(value);
  }

  render() {
    const { treeData, onChange, ...rest } = this.props;
    const tProps = {
      treeData,
      value: this.state.value,
      onChange: this.onChange,
      treeDefaultExpandAll: true,
      showCheckedStrategy: TreeSelect.SHOW_CHILD,
      placeholder: '选择参数'
    };
    return <TreeSelect {...tProps} { ...rest } />;
  }
}

TreeMultiSelect.propTypes = {
  treeData: PropTypes.array.isRequired,
  onChange: PropTypes.func.isRequired
}

export default TreeMultiSelect;
